package com.sunhao.appdemo;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView jump = findViewById(R.id.jump);
        jump.setOnClickListener(view -> {
            Intent intent = new Intent(this, BActivity.class);
            startActivityForResult(intent, Activity.RESULT_OK);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Toast.makeText(this, requestCode + "", Toast.LENGTH_SHORT).show();
//        if (requestCode == -1) {
//            if (data != null) {
//                String key = (String) data.getExtras().get("key");
//                System.out.println(key);
//                Toast.makeText(this, key, Toast.LENGTH_SHORT).show();
//            }
//        }

    }
}